#include<iostream>
#include"CTimeLine.h"

void display(ITimeLine * it);
int getLength(ITimeLine * it);

int main(){
    using namespace std;
    CTimeLine c1;
    CTimeLine c2;
    CTimeLine c3;
    CTimeLine head;
    // display(head.getNextTimeLine());
    head.setName("I have a head");
    c1.setName("second");
    c2.setName("third");
    c3.setName("fourth");
    head.add(&c1);
    head.add(&c2);
    head.add(&c3);
    if(getLength(&head) == 3)
        cout << "add test Done.\n";
    else
        cout << "add test error.\n";
    // display(&head);

    head.remove(&c3);
    if(getLength(&head) == 2)
        cout << "remove test Done.\n";
    else
        cout << "remove test error.\n";
    // display(&head);

    string s = "second";
    if(head.find(s)){
        if(head.find(s)->getName() == s)
            cout << "find test Done.\n";
        else
            cout << "find test error.\n";
    }else{
        cout << "not found.\n";
        cout << "find test Done.\n";
    }

    cout << "CTimeLine test Done.\n";
    system("pause");
    return 0;
}

void display(ITimeLine * it){
    ITimeLine * temp = it;
    using namespace std;
    if(temp){
        cout << it->getName() << endl;
        while(temp->getNextTimeLine()){
            temp = temp->getNextTimeLine();
            cout << temp->getName() << endl;
        }
    }else
        cout << "nullptr\n";
    cout << endl;
}

int getLength(ITimeLine * it){
    ITimeLine * temp = it;
    int i = 0;
    while(temp->getNextTimeLine()){
        temp = temp->getNextTimeLine();
        i++;
    }
    return i;
}